package com.wltt.product.ahuthr.holder;

import com.wltt.product.ahuthr.model.po.CurrentUserInfoBO;

import java.util.List;

public abstract class UserHolder {

    // 共享用户id
    private static InheritableThreadLocal<CurrentUserInfoBO> THREAD_LOCAL_USER = new InheritableThreadLocal<>();

    /**
     * 设置用户
     *
     * @param userPOJO 用户实体
     */
    public static void setUser(CurrentUserInfoBO userPOJO) {
        THREAD_LOCAL_USER.set(userPOJO);
    }

    /**
     * 获取用户
     *
     */
    public static CurrentUserInfoBO getUser() {
        return THREAD_LOCAL_USER.get();
    }

    /**
     * 获取用户id
     */
    public static Long getUserId() {
        return THREAD_LOCAL_USER.get().getId();
    }

    /**
     * 获取用户id
     */
    public static List<Long> getUserRoleIds() {
        return THREAD_LOCAL_USER.get().getRoleIds();
    }

    /**
     * 清空上下文
     */
    public static void remove() {
        THREAD_LOCAL_USER.remove();
    }
}
